﻿using Shop.BLL;
using Shop.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Shop.MVC.Areas.Admin.Controllers
{
    public class CategoryController : Controller
    {
        BaseManager<Category> cateManager=new BaseManager<Category>();
        public ActionResult Index(string title="")
        {
            //if (string.IsNullOrEmpty(title))
            //{
            //}
            var list = cateManager.GetList();
            return View(list);
        }

        [HttpGet]
        public ActionResult Create()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Create(Category category)
        {
            if (ModelState.IsValid)
            {
                cateManager.Add(category);
            }
            return View(category);
        }

        [HttpGet]public ActionResult Edit(int id)
        {
            var model=cateManager.GetEntity(id);
            return View(model);
        }
        [HttpPost]
        public ActionResult Edit(Category model)
        {
            if (ModelState.IsValid)
            {
                cateManager.Update(model);
            }
            return View(model);
        }

        public ActionResult Delete(int id)
        {
            cateManager.Delete(id);
            return RedirectToAction("Index");
        }

    }
}